// =================================================================================================
//
//	CopyEngine Framework
//	Copyright 2012 Eran. All Rights Reserved.
//
//	This program is free software. You can redistribute and/or modify it
//	in accordance with the terms of the accompanying license agreement.
//
// =================================================================================================

package edit
{
    import flash.display.MovieClip;
    import flash.geom.Rectangle;

    public class EditAssistLineComponent
    {
        private var mLayerMc:MovieClip;

        private var mHorizontalLeft:int;
        private var mHorizontalRight:int;
        private var mVerticalTop:int;
        private var mVerticalBottom:int;

        private var mImgBounds:Rectangle;

        public function EditAssistLineComponent()
        {
        }

        //==================================
        //== Initialize & Dispose
        //==================================

        public function initialize(_layerMc:MovieClip):void
        {
            mLayerMc = _layerMc;
        }

        //==================================
        //== Public Function
        //==================================

        public function refresh(_imgBounds:Rectangle,
                                _horizontalLeft:int,
                                _horizontalRight:int,
                                _verticalTop:int,
                                _verticalBottom:int):void
        {
            mImgBounds = _imgBounds;
            if (mImgBounds != null)
            {
                mHorizontalLeft = normalizeValue(_horizontalLeft, mImgBounds.left, mImgBounds.right);
                mHorizontalRight = normalizeValue(_horizontalRight, mImgBounds.left, mImgBounds.right);
                mVerticalTop = normalizeValue(_verticalTop, mImgBounds.top, mImgBounds.bottom);
                mVerticalBottom = normalizeValue(_verticalBottom, mImgBounds.top, mImgBounds.bottom);
                doRefreshDisplay();
            }
        }

        //==================================
        //== Private Function
        //==================================

        private function doRefreshDisplay():void
        {
            mLayerMc.graphics.clear();
            mLayerMc.graphics.lineStyle(1, 0x00FFFF);

            mLayerMc.graphics.moveTo(mHorizontalLeft, 0);
            mLayerMc.graphics.lineTo(mHorizontalLeft, mLayerMc.height);

            mLayerMc.graphics.moveTo(mHorizontalRight, 0);
            mLayerMc.graphics.lineTo(mHorizontalRight, mLayerMc.height);

            mLayerMc.graphics.moveTo(0, mVerticalTop);
            mLayerMc.graphics.lineTo(mLayerMc.width, mVerticalTop);

            mLayerMc.graphics.moveTo(0, mVerticalBottom);
            mLayerMc.graphics.lineTo(mLayerMc.width, mVerticalBottom);
        }


        private function normalizeValue(_value:int, _min:int, _max:int):int
        {
            _value = Math.max(_min, _value);
            _value = Math.min(_value, _max);
            return _value;
        }

    }
}
